package com.buybuyyi.stylistcrm.resource.controllers.order;

import com.buybuyyi.stylistcrm.resource.controllers.DefaultController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import stylistcrm.core.query.ResultPagerModel;
import stylistcrm.core.services.order.dto.InvoiceOrderDto;
import stylistcrm.core.services.order.dto.QueryOrderConditionDto;
import stylistcrm.core.services.order.enums.EnumExceptionCode;
import stylistcrm.core.services.order.exception.BizException;
import stylistcrm.core.services.order.service.InvoiceOrderService;

/**
 * Created by cheny on 2016/9/6.
 */
@Controller
@RequestMapping("/order")
public class InvoiceOrderController extends DefaultController{

    @Autowired
    private InvoiceOrderService invoiceOrderService;
    @ResponseBody
    @RequestMapping("/createinvoiceorder")
    public Boolean createInvoiceOrder(InvoiceOrderDto invoiceOrder) throws BizException {
        Long currentUserId=super.checkLogin();
        if(null==invoiceOrder){
            throw new BizException(EnumExceptionCode.EC0001);
        }
        invoiceOrder.setDesignerId(currentUserId.intValue());
        Boolean saveFlag=invoiceOrderService.createInvoiceOrder(currentUserId.intValue(),invoiceOrder);
        return saveFlag;
    }
    @ResponseBody
    @RequestMapping("/getinvoiceorderpagelist")
    public ResultPagerModel<InvoiceOrderDto> getInvoiceOrderPageList(QueryOrderConditionDto queryCondition) throws BizException {
        Long userId=super.checkLogin();
        if(null==queryCondition){
            throw new BizException(EnumExceptionCode.EC0001);
        }
        queryCondition.setDesignerId(userId.intValue());
        return invoiceOrderService.getPageList(queryCondition);
    }
    @ResponseBody
    @RequestMapping("/getinvoiceorderdetail")
    public InvoiceOrderDto getInvoiceOrderDetail(Integer orderId) throws BizException {
        super.checkLogin();
        if(null==orderId){
            throw new BizException(EnumExceptionCode.EC0001);
        }
        return invoiceOrderService.selectByPrimaryKey(orderId);
    }
}
